package beyjava.dbUtil;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * this class is used for database connection
 * @author BEYJAVA
 *
 */
public class ConnectionManager {
	/**
	 * classname
	 */
	public  String classname ="com.mysql.jdbc.Driver";
    private String username = "root";
	private String password = "";
	private String url      ="jdbc:mysql://localhost:3306/hrd?zeroDateTimeBehavior=convertToNull";
	private static  ConnectionManager  connectioninstance = null;

	/**
	 * @return ConnectionManager
	 */
	public static synchronized  ConnectionManager  getInstance(){
	    if(connectioninstance == null){
	    	connectioninstance = new ConnectionManager();
	    	
	    }
	    return connectioninstance;
	}
	/**
	 * @return Connection
	 */
	public  Connection getConnection(){	 
        Connection conn = null;
        try{
        	Class.forName(classname);
        	conn = DriverManager.getConnection(url,username,password);
       
        }
        
        catch (ClassNotFoundException e) {
	       System.out.println(e.getMessage());
        } catch (SQLException e) {
        	 System.out.println(e.getMessage());
        }
        return conn;
	}
	/**
	 * @param conn
	 */
	public void closeConnection(Connection conn){
	  try {
		  conn.close();
	  } catch (SQLException e) {
		  e.printStackTrace();
	  }
	} 
}
